import sys, logging, traceback
from google.appengine.api import memcache
from google.appengine.api import mail
class BaseHandler(webapp.RequestHandler):
	def handle_exception(self, exception, debug_mode):
		exception_name = sys.exc_info()[0].__name__
		exception_details = str(sys.exc_info()[1])
		exception_traceback = ''.join(traceback.format_exception(*sys.exc_info()))
		logging.error(exception_traceback)
		exception_expiration = 3600 # seconds (max 1 mail per hour for a particular exception)
		mail_admin = "jackson.h.miller@gmail.com" # must be admin for the application
		sitename = "Urlzen"
		throttle_name = 'exception-'+exception_name
		throttle = memcache.get(throttle_name)
		if throttle is None:
			memcache.add(throttle_name, 1, exception_expiration)
			subject = '[%s] exception [%s: %s]' % (sitename, exception_name, exception_details)
			mail.send_mail_to_admins(sender=mail_admin,subject=subject,body=exception_traceback)ort."}]}')
	

